package com.blog.dazi.Controller;

import com.blog.dazi.Service.ContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.bind.DefaultValue;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/dazi/content")
public class ContentController {
    @Autowired
    private ContentService contentService;

    /**
     * 查看列表 发布时间倒序
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("list")
    public List<Map<String,Object>> list(@RequestParam(value = "pageNum" ,required = false,defaultValue = "1") int pageNum, @RequestParam(value = "pageSize" ,required = false,defaultValue = "9")int pageSize){
        return contentService.list(pageNum,pageSize);
    }

    /**
     * 根据当前用户查看列表
     * @param daziNum
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/findByDazi/{daziNum}")
    public List<Map<String,Object>> findByDazi(@PathVariable("daziNum") String daziNum, @RequestParam(value = "pageNum" ,required = false,defaultValue = "1") int pageNum, @RequestParam(value = "pageSize" ,required = false,defaultValue = "9")int pageSize){
        return contentService.findByDazi(daziNum,pageNum,pageSize);
    }

    /**
     * 附近的列表
     * @param tel
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/nearby")
    public List<Map<String,Object>> findNearbyByTel(String tel, @RequestParam(value = "pageNum" ,required = false,defaultValue = "1") int pageNum, @RequestParam(value = "pageSize" ,required = false,defaultValue = "9")int pageSize){
        return contentService.findNearbyByTel(tel,pageNum,pageSize);
    }

    /**
     *  TODO 关注列表
     * @param tel
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/focus")
    public List<Map<String,Object>> findFocusByTel(String tel, @RequestParam(value = "pageNum" ,required = false,defaultValue = "1") int pageNum, @RequestParam(value = "pageSize" ,required = false,defaultValue = "9")int pageSize){
        return contentService.findFocusByTel(tel,pageNum,pageSize);
    }

    /**
     * 查询列表 按 时间 和距离排序
     * @param content
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/search")
    public List<Map<String,Object>> search(String content, @RequestParam(value = "pageNum" ,required = false,defaultValue = "1") int pageNum, @RequestParam(value = "pageSize" ,required = false,defaultValue = "9")int pageSize){
        return contentService.search(content,pageNum,pageSize);
    }

    @GetMapping("/findById")
    public Map<String,Object> findById(int id){
        return contentService.findById(id);
    }

    /**
     * 根据发布id查找评论
     * @param contentId
     * @return
     */
    @GetMapping("/message/findByContentId")
    public List<Map<String, Object>> findByContentId(int contentId){
        return contentService.findByContentId(contentId);
    }

    /**
     * 保存评论
     * @param message
     * @return
     */
    @GetMapping("/message/save")
    public int messageSave(@RequestBody String message){
        return contentService.messageSave(message);
    }

    /**
     * 发布消息
     * @param message
     * @return
     */
    @PostMapping("/say")
    public int say(@RequestBody String message){
        return contentService.say(message);
    }

    /**
     * 点赞
     * @param
     * @return
     */
    @GetMapping("/good")
    public int good(int id,int good){
        return contentService.good(id,good);
    }
}
